//
//  NewFeatureCell.m
//  weibo-OC
//
//  Created by diyuyma on 16/3/17.
//  Copyright © 2016年 zhangkaiyun. All rights reserved.
//

#import "NewFeatureCell.h"
#import "Masonry.h"


@interface NewFeatureCell ()
@property (nonatomic, strong)UIImageView *iconImage;
@property (nonatomic, strong)UIButton *startButton;
@end

@implementation NewFeatureCell

- (void)setIndex:(NSInteger)index {
    _index = index;
    self.iconImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld", _index + 1]];
    self.startButton.hidden = true;
}

- (void)startAnimation {
    self.startButton.transform = CGAffineTransformMakeScale(0, 0);
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:0 animations:^{
        self.startButton.hidden = false;
        self.startButton.transform = CGAffineTransformMakeScale(1, 1);
    } completion:^(BOOL finished) {

    }];
}

// MARK: 3.重写父类的构造方法 调用设置 UI
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    [self setupUI];
    return self;
}

// MARK: 2.设置 UI
- (void)setupUI {
    // 1.添加子控件
    [self.contentView addSubview:self.iconImage];
    [self.contentView addSubview:self.startButton];
    
    // 2.设置约束
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
    [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-200);
        make.centerX.equalTo(self.contentView.mas_centerX);
    }];

    // 3.设置点击事件
    [self.startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
}

// MARK: 1.懒加载所有子控件
- (UIImageView *)iconImage {
    if (_iconImage == nil) {
        _iconImage = [[UIImageView alloc] init];
    }
    return _iconImage;
}

- (UIButton *)startButton {
    
    if (_startButton == nil) {
        _startButton = [[UIButton alloc] init];
        [_startButton initWithTitle:@"开始体验" WithBackImage:@"new_feature_finish_button" WithColor:nil WithImage:nil WithSize:0];
    }
    return _startButton;
}

//MARK: 按钮的点击事件
- (void)start {
    NSLog(@"start");
    [[NSNotificationCenter defaultCenter] postNotificationName:AppSwitchRootViewControler object:nil];
}

@end
